package com.scf.guaranty.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scf.guaranty.dao.GuarantyDao;
import com.scf.guaranty.entity.Guaranty;
import com.scf.guaranty.service.GuarantyService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * 担保物管理表(Guaranty)表服务实现类
 *
 * @author makejava
 * @since 2021-11-12 17:13:02
 */
@Service("guarantyService")
public class GuarantyServiceImpl implements GuarantyService {
    @Resource
    private GuarantyDao guarantyDao;


    @Override
    public PageInfo<Guaranty> getAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<Guaranty>(guarantyDao.getAll());
    }

    @Override
    public void add(Guaranty guaranty) {
        SimpleDateFormat date=new SimpleDateFormat("yyyy-MM-dd");
        String str=date.format(new Date());
        guaranty.setUpdateTime(str);
        guaranty.setStatus("1");
        SimpleDateFormat date1=new SimpleDateFormat("yyyyMMdd");
        String str1=date1.format(new Date())+ (new Random().nextInt(9000)+1000);
        guaranty.setSerial(str1);
        guarantyDao.add(guaranty);

    }

    @Override
    public void update(Guaranty guaranty) {
        guarantyDao.update(guaranty);
    }

    @Override
    public void deleteById(int id) {
            guarantyDao.deleteById(id);
    }

    @Override
    public PageInfo<Guaranty> getByCondition(String name, String type, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<Guaranty>(guarantyDao.getByCondition(name, type));
    }

    @Override
    public PageInfo<Guaranty> getByApproval(String status, String name, String type, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<Guaranty>(guarantyDao.getByApproval(status,name, type));
    }

    @Override
    public List<Guaranty> getById(int id) {
        return guarantyDao.getById(id);
    }

    @Override
    public void pass(int id) {
        guarantyDao.pass(id);
    }

    @Override
    public void reject(int id) {
        guarantyDao.reject(id);
    }
}
